home *** CD-ROM | disk | FTP | other *** search
- {MEAN AND STANDARD DEVIATION GARY CURTIS NEWPORT
-
- PURPOSE: This procedure reads a set of (real or integer) values from
- an array and calculates the mean and (unbiased) standard
- deviation of that set.
-
- ALGORITHM: See Alan R. Miller, Pascal Programs for Scientists and
- Engineers, SYBEX, 1981,. pp. 21-29.
-
- USE : The following declarations are used:
-
- CONST max = (some integer);
- TYPE XarrayType = array[1..max] of integer; (or real)
- VAR Xarray : XarrayType;
- Mean, Std_Dev : real;
- N : integer;
-
-
- Include MEANSTD
- after declarations. Fill Xarray with N values,
- and call
- MEANSTD(Xarray, N, Mean, Std_Dev);
-
- The appropriate values will be stored in Mean and Std_Dev.
-
- }
-
- procedure MEANSTD
- (VAR x : XarrayType;
- N : integer;
- VAR Mean : real;
- VAR Sigma : real );
-
- VAR
- i : integer;
- sum_x,
- sum_sq : real;
-
- BEGIN {MEANSTD}
- sum_x := 0;
- sum_sq := 0;
- FOR i := 1 to N do
- BEGIN
- sum_x := sum_x + x[i];
- sum_sq := sum_sq + (x[i] * x[i]);
- END; {FOR}
- Mean := sum_x/N;
- Sigma := SQRT((sum_sq - ((SQR(sum_x))/N))/(N - 1))
-
- { NOTE : The usual definition of the standard deviation uses
- N, rather than N - 1, in the denominator. See
- William L. Hays, Statistics for the Social sciences,
- New York: Holt, Rinehart and Winston, 1973.
- pp. 283-285 for a discussion of the difference. }
-
- END; {MEANSTD}
-